#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = "jzp";

import random;
from pyecharts.faker import Faker;
from pyecharts import options as opts;
from pyecharts.charts import Bar, Bar3D, Line, Line3D, Pie, Map, Geo, Funnel, Grid, Tab, Page;

'''
图表测试
'''

# 测试数据
def faker_test():
    print(Faker.choose());
    print(Faker.values());
    print(Faker.country);
    print(Faker.cars);
    print(Faker.visual_color);
    print(Faker.rand_color());

# 线状图
def pyecharts_line():
    Line().add_xaxis(
        xaxis_data=Faker.choose()
    ).add_yaxis(
        series_name="line1",
        y_axis=Faker.values(1, 100),
        itemstyle_opts=opts.ItemStyleOpts(color=Faker.rand_color())
    ).add_yaxis(
        series_name="line2",
        y_axis=Faker.values(1, 100),
        itemstyle_opts=opts.ItemStyleOpts(color=Faker.rand_color())
    ).set_global_opts(
        title_opts=opts.TitleOpts(title="线装图1", subtitle="线装图副标题", pos_left="10%")
    ).render(
        path="D:/temp/pyecharts_line.html"
    )

#柱状图
def pyecharts_bar():
    Bar().add_xaxis(
        xaxis_data=Faker.choose()
    ).add_yaxis(
        series_name="bar1",
        y_axis=Faker.values(1, 100),
        itemstyle_opts=opts.ItemStyleOpts(color=Faker.rand_color())
    ).add_yaxis(
        series_name="bar2",
        y_axis=Faker.values(1, 100),
        itemstyle_opts=opts.ItemStyleOpts(color=Faker.rand_color())
    ).set_global_opts(
        title_opts=opts.TitleOpts(title="柱状图1", subtitle="柱状图副标题", pos_left="10%")
    ).render(
        path="D:/temp/pyecharts_bar.html"
    )

#柱状图
def pyecharts_pie():
    Pie().add(
        series_name="饼图名称",
        # 数据格式[[key, value], [key, value], ...], 用 zip 函数将两个 list 进行组合
        data_pair=[list(z) for z in zip(Faker.choose(), Faker.values())],
        # 中心点的 x、y 位置
        center=["50%", "50%"],
    ).set_series_opts(
        label_opts=opts.LabelOpts(
            formatter="{b}: {c}",
            color=Faker.rand_color(),
        )
    ).set_global_opts(
        title_opts=opts.TitleOpts(title="斌状图1", subtitle="饼状图副标题", pos_left="10%")
    ).render(
        path="D:/temp/pyecharts_pie.html"
    )

# 折线 3D 图
def line_3d_fun():
    # 三维数据，定义 x、y 长度，z 数值随机
    data = [(i, j, random.randint(1, 20)) for i in range(7) for j in range(10)];
    print(len(data), data);
    Line3D().add(
        # 添加 x、y、z 轴数据，并设置属性
        series_name="",
        data=data,
        xaxis3d_opts=opts.Axis3DOpts(Faker.choose(), type_="value"),
        yaxis3d_opts=opts.Axis3DOpts(Faker.choose(), type_="value"),
        zaxis3d_opts=opts.Axis3DOpts(Faker.values(), type_="value"),
        # 添加旋转效果
        grid3d_opts=opts.Grid3DOpts(
            width=100, depth=100, rotate_speed=150, is_rotate=True
        ),
    ).set_global_opts(
        # 设置图表属性
        # 视觉配置
        visualmap_opts=opts.VisualMapOpts(max_=20),
        title_opts=opts.TitleOpts(title="主标题", subtitle="副标题")
    ).render(
        # 设置输出路径
        path="D:/temp/pyecharts_line3d.html"
    );

if __name__ == '__main__':
    line_3d_fun();